/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.elf.gwt.common.client.model;

import com.google.gwt.json.client.JSONObject;

/**
 *  
 */
public class LanguageModel extends AbstractModel
{
	protected String code;
	protected boolean defaultCode;
	protected int id = 0;
	protected String image;
	protected String name;

	
	public LanguageModel(int languagesId, String name, String code, String image, boolean defaultCode)
	{
		update(languagesId, name, code, image, defaultCode);
	}
	
	public LanguageModel(JSONObject jsonObject, String defaultCodeStr)
	{
		id = convertToInteger(jsonObject,"id");
		name = convertToString(jsonObject,"name");
		code = convertToString(jsonObject,"code");
		image = convertToString(jsonObject,"image");
		
		defaultCode = false;
		if (defaultCodeStr.equals(code)) defaultCode = true;
	}

	public void update(LanguageModel model)
	{
		update(model.getId(), model.getName(), model.getCode(), model.getImage(), model.isDefaultCode());
	}
	
	public void update(int languagesId, String name, String code, String image, boolean defaultCode)
	{
		this.id = languagesId;
		this.name = name;
		this.code = code;
		this.image = image;
		this.defaultCode = defaultCode;
	}
	
	public String getCode() {
		return code;
	}
	public int getId() {
		return id;
	}

	public String getImage() {
		return image;
	}

	public String getName() {
		return name;
	}

	public boolean isDefaultCode() {
		return defaultCode;
	}
}
